<!-- Dom模板 -->
<template>
  <div>
    <!-- Dom内容 -->
    <div class="addBox">
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
        @keyup.enter.native="submitForm('ruleForm')"
      >
        <p>修改会员数据</p>
        <el-form-item label="序号" prop="serialNumber">
          <el-input v-model="ruleForm.serialNumber"></el-input>
        </el-form-item>
        <el-form-item label="会员号" prop="mid">
          <el-input v-model="ruleForm.mid"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="会员类别" prop="MemType">
          <el-input v-model="ruleForm.MemType"></el-input>
        </el-form-item>
        <el-form-item label="折扣" prop="discount">
          <el-input v-model="ruleForm.discount"></el-input>
        </el-form-item>
        <el-form-item label="消费金额" prop="Monetary">
          <el-input v-model="ruleForm.Monetary"></el-input>
        </el-form-item>
        <el-form-item label="积分" prop="integrate">
          <el-input v-model="ruleForm.integrate"></el-input>
        </el-form-item>
        <el-form-item label="储值余额" prop="storedMoney">
          <el-input v-model="ruleForm.storedMoney"></el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="tel">
          <el-input v-model="ruleForm.tel"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >确定</el-button
          >
          <el-button type="primary" @click="cancelForm('ruleForm')"
            >取消</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
// import a from './a'; // 引入组件
import * as apis from "../../api/vip";
export default {
  name: "",
  props: ["flag", "onedata"],
  data() {
    return {
      msg: "测试",
      ruleForm: {
        serialNumber: "",
        mid: "",
        name: "",
        MemType: "",
        discount: "",
        Monetary: "",
        integrate: "",
        storedMoney: "",
        tel: "",
      },
      rules: {
        serialNumber: [
          { required: true, message: "请输入序号", trigger: "blur" },
          { min: 3, max: 5, message: "长度5个字符", trigger: "blur" },
        ],
        mid: [
          { required: true, message: "请输入会员号", trigger: "blur" },
          { min: 3, max: 5, message: "长度大于1个数字", trigger: "blur" },
        ],
        name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
          { min: 3, max: 5, message: "长度大于2个字符", trigger: "blur" },
        ],
        MemType: [
          { required: true, message: "请输入会员类别", trigger: "blur" },
          { min: 3, max: 5, message: "长度2个字符", trigger: "blur" },
        ],
        discount: [
          { required: true, message: "请输入折扣", trigger: "blur" },
          { min: 3, max: 5, message: "长度大于1字符", trigger: "blur" },
        ],
        Monetary: [
          { required: true, message: "请输入消费金额", trigger: "blur" },
          { min: 3, max: 5, message: "长度大于1个字符", trigger: "blur" },
        ],
        integrate: [
          { required: true, message: "请输入积分", trigger: "blur" },
          { min: 3, max: 5, message: "长度大于1个字符", trigger: "blur" },
        ],
        storedMoney: [
          { required: true, message: "请输入储值余额", trigger: "blur" },
          { min: 3, max: 5, message: "长度大于1个字符", trigger: "blur" },
        ],
        tel: [
          { required: true, message: "请输入手机号码", trigger: "blur" },
          { min: 3, max: 5, message: "长度11个字符", trigger: "blur" },
        ],
      },
    };
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    console.log(this.onedata);
    let {
      serialNumber,
      mid,
      name,
      MemType,
      discount,
      Monetary,
      integrate,
      storedMoney,
      tel,
    } = this.onedata;
    this.ruleForm.serialNumber = serialNumber;
    this.ruleForm.mid = mid;
    this.ruleForm.name = name;
    this.ruleForm.MemType = MemType;
    this.ruleForm.discount = discount;
    this.ruleForm.Monetary = Monetary;
    this.ruleForm.integrate = integrate;
    this.ruleForm.storedMoney = storedMoney;
    this.ruleForm.tel = tel;
  },
  // Vue方法定义
  methods: {
    //确定添加
    submitForm() {
      this.$confirm("此操作将永久修改该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          apis
            .vipfix({
              serialNumber: this.ruleForm.serialNumber,
              mid: this.ruleForm.mid,
              name: this.ruleForm.name,
              MemType: this.ruleForm.MemType,
              discount: this.ruleForm.discount,
              Monetary: this.ruleForm.Monetary,
              integrate: this.ruleForm.integrate,
              storedMoney: this.ruleForm.storedMoney,
              tel: this.ruleForm.tel,
            })
            .then((res) => {
              console.log(res.data);
            });
          this.$message({
            type: "success",
            message: "修改成功!",
          });
          this.$emit("fixClose", !this.flag);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消修改",
          });
        });
    },
    //取消添加
    cancelForm() {
      this.$alert("还没有修改，确定关闭弹窗？", "关闭", {
        confirmButtonText: "确定",
        callback: (action) => {
          this.$message({
            type: "success",
            message: "关闭成功",
          });
        },
      });
      this.$emit("nofixClose", !this.flag);
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
/* @import url(''); 引入css类 */
.addBox {
  background: #fff;
  width: 400px;
  height: 580px;
  position: fixed;
  top: calc(50% - 200px);
  left: calc(50% - 340px);
  z-index: 2;
  border-radius: 6px;
}
p {
  width: 100%;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 22px;
  font-weight: bold;
}
</style>
<style scoped>
/* @import url(''); 引入css类 */
.addBox .el-form-item,
.el-form-item__content,
.el-form-item__label {
  height: 30px;
  line-height: 30px;
}

.addBox .el-button,
.el-button--primary {
  padding: 8px 20px;
}
</style>
<style scoped>
/* @import url(''); 引入css类 */
.addBox .el-input {
  position: relative;
  font-size: 14px;
  display: inline-block;
  width: 78%;
}
/*.addBox .el-form-item[data-v-9c613b62],
.el-form-item__content[data-v-9c613b62],
.el-form-item__label[data-v-9c613b62] {
  height: 21px;
  line-height: 30px;
}*/
</style>
